package com.zxl.admin.service;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageHelper;
import com.zxl.common.constant.DeleteStatusConstant;
import com.zxl.common.exception.BusinessException;
import com.zxl.common.mapper.SysInformationMapper;
import com.zxl.common.model.bo.information.InformationSaveBo;
import com.zxl.common.model.pojo.SysInformation;
import com.zxl.common.model.pojo.SysInformationGroup;
import com.zxl.common.model.query.information.InformationQuery;
import com.zxl.common.model.vo.information.InformationVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zxw
 * @date 2023/4/24
 */
@Service
public class InformationService {
    @Resource
    private SysInformationMapper sysInformationMapper;


    public void add(InformationSaveBo bo) {
        SysInformation entity = new SysInformation();
        BeanUtil.copyProperties(bo, entity);
        sysInformationMapper.insert(entity);
    }


    public void update(InformationSaveBo bo) {
        if(bo.getId() == null) {
            throw new BusinessException("id为空");
        }
        SysInformation entity = new SysInformation();
        BeanUtil.copyProperties(bo, entity);
        sysInformationMapper.updateById(entity);
    }


    public List<InformationVo> getList(InformationQuery query) {
        PageHelper.startPage(query.getPageNumber(), query.getPageSize());
        List<InformationVo> list = sysInformationMapper.getList(query);
        return list;
    }

    public void delete(Integer id) {
        if(id == null){
            throw new BusinessException("id不允许为空");
        }
        SysInformation entity = new SysInformation();
        entity.setId(id);
        entity.setDeleteStatus(DeleteStatusConstant.HAS_DELETE.getCode());
        sysInformationMapper.updateById(entity);
    }
}
